import { createApp } from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";
import axios from "axios";
import 'easymde/dist/easymde.min.css'
//引入bootstrap样式
import "bootstrap/dist/css/bootstrap.min.css";

axios.defaults.baseURL = "http://apis.imooc.com/api";

axios.interceptors.request.use((config) => {
  // get请求直接添加到url中
  config.params = { ...config.params, icode: "C47F851009F72942" };
  //   其他请求，添加到body中
  // 如果是文件上传，添加到FromData中
  if (config.data instanceof FormData) {
    config.data.append("icode", "C47F851009F72942");
  } else {
    // 普通的body对象添加到data中
    // config.data=(...config.data, icode:'C47F851009F72942')
    config.data = { ...config.data, icode: "C47F851009F72942" };
  }
  store.commit("setLoading", true);
  // 解决了提示报错信息不能重复显示的问题
  store.commit('setError',{statrus:false,message:''})
  return config;
});

axios.interceptors.response.use(
  (config) => {
    setTimeout(() => {
      store.commit("setLoading", false);
    }, 500);
    return config;
  },
  (e) => {
    const { error } = e.response.data;
    store.commit("setError", { stateus: true, message: error });
    store.commit("setLoading", false);
    return Promise.reject(error)
  }
);

// axios.get('/columns').then(res => {
//     console.log(res.data)
// })

// axios.get('columns',{params:{currentPage:'1',pageSiza:'10'}}).then(res => {
//     console.log(res.data)
// })

createApp(App).use(store).use(router).mount("#app");
